TARGET   = keyboard.ihx
CFLAGS   = --model-large -I../common -I../mcu-lib -DNRF24LE1
#CFLAGS  += -DDBG_MODE=0
LFLAGS   = --code-loc 0x0000 --code-size 0x4000 --xram-loc 0x0000 --xram-size 0x400
ASFLAGS  = -plosgff
RELFILES = main.rel matrix.rel layers.rel layer_defs.rel ctrl_settings.rel sleeping.rel rf_ctrl.rel rf_addr.rel nrfdbg.rel nrfutils.rel nRF24L.rel crtxinit.rel

VPATH   = ../common:../mcu-lib

hex: $(TARGET)

$(TARGET): $(RELFILES)
	sdcc $(CFLAGS) $(LFLAGS) $(RELFILES) -o $(TARGET)
	grep "ROM/EPROM" keyboard.mem

%.rel: %.c
	sdcc $(CFLAGS) -c $<

%.rel: %.asm
	sdas8051 $(ASFLAGS) $@ $< 

clean:
	rm --force *.ihx *.lnk *.lst *.map *.rel *.rst *.sym *.mem *.lk *.asm *.lk *.cdb *.omf

all: clean hex

flash: clean hex
	nrfburn -f 16 -w $(TARGET)
